package com.coldworks.coldjoke.adapter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coldworks.coldjoke.R;
import com.coldworks.coldjoke.model.JokeEntity;
import com.coldworks.coldjoke.model.JokeModel;
import com.coldworks.coldjoke.ui.JokeQuickCell;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class JokeQuickAdapter extends BaseAdapter {
	protected final Logger log = LoggerFactory.getLogger(this.getClass());
	private Context context;
	private JokeEntity jokeEntity;
	private int lastSelect = 0;
	private int currSelect = 0;

	public JokeQuickAdapter(Context context, JokeEntity jokeEntity) {
		this.jokeEntity = jokeEntity;
		this.context = context;
	}

	public void setJokeEntity(JokeEntity jokeEntity) {
		this.jokeEntity = jokeEntity;
	}

	@Override
	public int getCount() {
		if (jokeEntity.manager == null) {
			return 2;
		}
		return jokeEntity.manager.getListShow().size();
	}

	@Override
	public JokeModel getItem(int position) {
		if (position == 0) {
			return null;
		} else {
			return jokeEntity.manager.getListShow().get(position);
		}

	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		lastSelect = currSelect;
		currSelect = position;

		if (convertView == null) {
			convertView = new JokeQuickCell(this.context);
		}
		JokeModel jokeModel = jokeEntity.manager.getListShow().get(position);
		((JokeQuickCell) convertView).setData(position, jokeModel,
				jokeEntity.manager.getJokesSort(), false);
		return convertView;
	}

	public int getLastSelect() {
		return lastSelect;
	}

	public int getCurrSelect() {
		return currSelect;
	}

}
